package com.geeka.d12.work.chatroom;

import java.io.*;
import java.net.Socket;

public class OtherChatThread implements Runnable{
    private Socket socket;
    public OtherChatThread(Socket socket) {
        this.socket=socket;
    }

    @Override
    public void run() {
        System.out.println("runOneSocket now sockets " );

        String cname = socket.getInetAddress() + "" + socket.getPort();
        try {
            InputStream ips = socket.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(ips));
            String s = null;

            OutputStream ops =socket.getOutputStream();
            PrintStream ps = new PrintStream(ops);
            ps.println();

            while ((s = br.readLine()) != null) {
                System.out.println(cname+" : "+s);
                ps.println("服务器对你说 你对我说了,现在我让大家都看到: "+s);
            }
        } catch (IOException e) {
            System.out.println(" socket异常: " + e.getMessage());
            e.printStackTrace();
        }
    }
}
